* SM-E13

set scheme stcolor
version 17
use ../Metadata/tess_analysisdata.dta, clear	
	
	
* outcome variables

	tab hyp_true if insample==1

	cap drop hyp_true hyp_true_insample hyp_anytrue_insample total_hyp_true_insample hyp_10pct_supp_insample successfulexp_insample
	
	gen hyp_true=1 if twop<0.05 & rightdir=="yes"
	replace hyp_true=1 if twop<0.05 & rightdir==""
	replace hyp_true=0 if twop>=0.05 
	replace hyp_true=0 if twop<0.05 & rightdir=="no"
	
	tab hyp_true if insample==1
	
* at least one hypothesis was supported in the study
	* true hypotheses insample
	gen hyp_true_insample= hyp_true if insample==1

	egen hyp_anytrue_insample=max(hyp_true_insample), by(vendor_id)
	lab var hyp_anytrue_insample "At least 1 hypothesis supported"


* at least 10% of hypotheses supported 
	// total hypotheses supported 
	egen total_hyp_true_insample=sum(hyp_true_insample), by(vendor_id)

	gen temp=total_hyp_insample*0.1
	gen hyp_10pct_supp_insample=1 if total_hyp_true_insample>=temp & total_hyp_true_insample!=.
	replace hyp_10pct_supp_insample=0 if total_hyp_true_insample<temp & temp!=.
	drop temp
	sum hyp_10pct_supp_insample
	lab var hyp_10pct_supp_insample "At least 10% hypotheses supported"	
	
* successful experiment (at least 1 hyp true if #hyp<=10; or 10% hyp true if #hyp>10)	
	gen successfulexp_insample=hyp_anytrue_insample if total_hyp_insample<=10
	replace successfulexp_insample=hyp_10pct_supp_insample if total_hyp_insample>10

	lab var successfulexp_insample "Successful study"	
	
************************************
	
	
	
cap frame change default
cap frame drop results
frame create results strL varname mean se ul ll str8 N color
	
	gen faculty = (title == 3 | title == 4 | title == 5)
	
	proportion hyp_true if faculty == 1 & insample == 1, level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results ("Faculty") (`mean') (`se') (`ll') (`ul') ("N=`N'") (1)

	proportion hyp_true if faculty == 0 & insample == 1, level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results ("Non-faculty") (`mean') (`se') (`ll') (`ul') ("N=`N'")	(1)

	gen multiauthor = numauthors > 1 if numauthors < .
		
	proportion hyp_true if multiauthor == 0 & insample == 1, level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results ("Sole-authored") (`mean') (`se') (`ll') (`ul') ("N=`N'") (2)

	proportion hyp_true if multiauthor == 1 & insample == 1, level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results ("Co-authored") (`mean') (`se') (`ll') (`ul') ("N=`N'")	(2)

	cap drop polisci
	gen polisci = (discipline == 5)
	
	proportion hyp_true if polisci == 1 & insample == 1, level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results (`""Political" "science""') (`mean') (`se') (`ll') (`ul') ("N=`N'")	(3)

	proportion hyp_true if polisci == 0 & insample == 1, level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results (`""Not political" "science""') (`mean') (`se') (`ll') (`ul') ("N=`N'")	(3)

	
	frame results {
		
		cap drop xlabel
		gen xlabel=_n
		labmask xlabel, values(varname)

		cap drop mlabel
		gen mlabel=0.025
		
		graph twoway ///
		(bar mean xlabel , barw(0.8) colorvar(color) colorlist(stc1%50 stc2%50 stc3%50 ) colordiscrete lc(none)) ///
		(rcap ll ul xlabel ,lc(gs7)) ///	
		(scatter mlabel xlabel , ///
msym(none) mlab(N) mlabpos(0) mlabcolor(black) mlabsize(2.4) mlabangle(hor)) ///
		, ///		
			ytitle("Pr(supported hypothesis)", size(small) margin(r=2)) ///
			xlabel(, labsize(small) angle(hor) valuelabel nogrid) ///
			xtitle(" ", margin(b=2)) ///
			ylabel(0(0.1).5, labsize(small) gmax gmin nogrid) ///
			title("{it: Hypothesis-level support}" " ", justification(left) position(11) span) ///
			graphregion(color(white)) ///
			scheme(stcolor) ///
			legend(off) clegend(off) ///
			xsize(8) ysize(5.5) ///
			name(inv_hyplevel, replace)
	
	}
 
 
 use ../Metadata/tess_analysisdata.dta, clear	
	
* outcome variables

	cap drop hyp_true hyp_true_insample hyp_anytrue_insample total_hyp_true_insample hyp_10pct_supp_insample successfulexp_insample
	
	gen hyp_true=1 if twop<0.05 & rightdir=="yes"
	replace hyp_true=1 if twop<0.05 & rightdir==""
	replace hyp_true=0 if twop>=0.05 
	replace hyp_true=0 if twop<0.05 & rightdir=="no"
	

* at least one hypothesis was supported in the study
	* true hypotheses insample
	gen hyp_true_insample= hyp_true if insample==1

	egen hyp_anytrue_insample=max(hyp_true_insample), by(vendor_id)
	lab var hyp_anytrue_insample "At least 1 hypothesis supported"


* at least 10% of hypotheses supported 
	// total hypotheses supported 
	egen total_hyp_true_insample=sum(hyp_true_insample), by(vendor_id)

	gen temp=total_hyp_insample*0.1
	gen hyp_10pct_supp_insample=1 if total_hyp_true_insample>=temp & total_hyp_true_insample!=.
	replace hyp_10pct_supp_insample=0 if total_hyp_true_insample<temp & temp!=.
	drop temp
	sum hyp_10pct_supp_insample
	lab var hyp_10pct_supp_insample "At least 10% hypotheses supported"	
	
* successful experiment (at least 1 hyp true if #hyp<=10; or 10% hyp true if #hyp>10)	
	gen successfulexp_insample=hyp_anytrue_insample if total_hyp_insample<=10
	replace successfulexp_insample=hyp_10pct_supp_insample if total_hyp_insample>10

	lab var successfulexp_insample "Successful study"	
	
	tab successfulexp_insample if hyp_num==1 
	
************************************
	
	
cap frame change default
cap frame drop results
frame create results strL varname mean se ul ll str8 N color
	
	gen faculty = (title == 3 | title == 4 | title == 5)
	keep if hyp_num==1
	
	proportion successfulexp_insample if faculty == 1 , level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results ("Faculty") (`mean') (`se') (`ll') (`ul') ("N=`N'") (1)

	proportion successfulexp_insample if faculty == 0 , level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results ("Non-faculty") (`mean') (`se') (`ll') (`ul') ("N=`N'")	(1)

	gen multiauthor = numauthors > 1 if numauthors < .
		
	proportion successfulexp_insample if multiauthor == 0 , level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results ("Sole-authored") (`mean') (`se') (`ll') (`ul') ("N=`N'") (2)

	proportion successfulexp_insample if multiauthor == 1 , level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results ("Co-authored") (`mean') (`se') (`ll') (`ul') ("N=`N'")	(2)

	cap drop polisci
	gen polisci = (discipline == 5)
	
	proportion successfulexp_insample if polisci == 1 , level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results (`""Political" "science""') (`mean') (`se') (`ll') (`ul') ("N=`N'")	(3)

	proportion successfulexp_insample if polisci == 0 , level(83.4)		
	mat table = r(table)	
	local mean = table[1,2]
	local se = table[2,2]
	local ll = table[5,2]
	local ul = table[6,2]
	local N	 = table[7,1]+1		
	frame post results (`""Not political" "science""') (`mean') (`se') (`ll') (`ul') ("N=`N'")	(3)

	
	frame results {

		cap drop xlabel
		gen xlabel=_n
		labmask xlabel, values(varname)

		cap drop mlabel
		gen mlabel=0.05
		
		graph twoway ///
		(bar mean xlabel , barw(0.8) colorvar(color) colorlist(stc1%50 stc2%50 stc3%50)  colordiscrete lc(none)) ///
		(rcap ll ul xlabel ,lc(gs7)) ///	
		(scatter mlabel xlabel , ///
msym(none) mlab(N) mlabpos(0) mlabcolor(black) mlabsize(2.4) mlabangle(hor)) ///
		, ///		
			ytitle("Pr(positive result)", size(small) margin(r=2)) ///
			xlabel(, labsize(small) angle(hor) valuelabel nogrid) ///
			xtitle(" ", margin(b=2)) ///
			title("{it: Study-level positive result}" " ", justification(left) position(11) span) ///
			ylabel(0(0.2)1, labsize(small) gmax gmin nogrid) ///
			graphregion(color(white)) ///
			scheme(stcolor) ///
			legend(off) clegend(off) ///
			xsize(8) ysize(5.5) ///
			name(inv_explevel, replace)
	
	}
 
graph combine inv_hyplevel inv_explevel, col(1) ///
	ysize(6) xsize(5)
 

	
graph export "../Results/SM-E13-Figure-InvestigatorCharacteristics.pdf", replace		
	